//
//  HHYConfirePayVC.m
//  大股票
//
//  Created by apple on 2019/9/5.
//  Copyright © 2019 apple. All rights reserved.
//

#import "HHYConfirePayVC.h"

#import "HHYPayAlertView.h"
#import "RNMZhiFuCGVC.h"

@interface HHYConfirePayVC ()

@property (nonatomic, strong) UIView *contentView;
@property (weak, nonatomic) IBOutlet UILabel *totalLabel;
@property (weak, nonatomic) IBOutlet UITextField *bjTF;
@property (weak, nonatomic) IBOutlet UITextField *glfTF;
@property (weak, nonatomic) IBOutlet UIButton *sureBtn;

@end
@implementation HHYConfirePayVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = UIColor.whiteColor;
    
    [self setupSubViews];
    
    //    [self setupSubViews];

}

- (void)createNavi {
    [self setupNavi_White];
    self.navigationItem.title = @"支付确认";
}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self createNavi];
    
}

- (void)setupSubViews {
    [self.view addSubview:self.contentView];
    [self updateUIAfterLoadNib];
}

#pragma mark - 创建rightView
- (UIView *)createRightViewWithTitle:(NSString *)title {
    UILabel *leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 28)];
    leftLabel.textColor = UIColor.lightGrayColor;
    leftLabel.font = [UIFont systemFontOfSize:16];
    leftLabel.textAlignment = NSTextAlignmentRight;
    leftLabel.text = title;
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 28)];
    [view addSubview:leftLabel];
    return view;
}

- (void)updateUIAfterLoadNib {
    
    self.sureBtn.layer.cornerRadius = 8.0f;
    self.sureBtn.layer.masksToBounds = YES;
    NSInteger bj = [self.applyModel.tzbj integerValue];
    CGFloat glf = [self.applyModel.glf floatValue];
    self.totalLabel.text = [NSString stringWithFormat:@"￥%0.2f", bj+glf];
    self.bjTF.text = [NSString stringWithFormat:@"￥%@", self.applyModel.tzbj];
    self.glfTF.text = [NSString stringWithFormat:@"￥%@", self.applyModel.glf];

}

- (IBAction)payAction:(id)sender {
    
    if (![DGPUtil getZhiFuPwd]) {
        [HHYUtils textExampleLong:@"请先设置支付密码~"];
        return;
    }
    
   HHYPayAlertView *alertView =  [HHYPayAlertView showPayAlert];

    __weak typeof(self)wSelf = self;
    alertView.handler = ^(BOOL res, NSString * _Nonnull reason) {
        __strong typeof(self)sSelf = wSelf;
        if (res) {
            //保存model
            [sSelf.applyModel saveOrUpdate];
            [sSelf payCodeSuceessAction];
        } else {
            [HHYUtils textExampleLong:reason];
        }
    };

}

- (void)payCodeSuceessAction {
    __weak typeof(self)wSelf = self;
    CGFloat pay = [self.applyModel.glf floatValue] + [self.applyModel.tzbj integerValue];

    [DGPUtil calculatemoney:@"提现" by:pay successCallback:^{
        __strong typeof(self)sSelf = wSelf;
        RNMZhiFuCGVC *svc = [RNMZhiFuCGVC new];
        [sSelf.navigationController pushViewController:svc animated:YES];
    } failedCallback:^{
        [HHYUtils textExampleLong:@"支付失败"];
    }];
   
}

#pragma mark - getter

- (UIView *)contentView {
    if (!_contentView) {
        UINib *nib = [UINib nibWithNibName:@"HHYConfirmPayView" bundle:nil];
        NSArray *objs = [nib instantiateWithOwner:self options:nil];
        _contentView = objs[0];
        _contentView.frame = CGRectMake(0, 0, hhy_kScreenWidth, 764);
    }
    return _contentView;
}

@end
